use std::fs::{File, create_dir_all};
use std::io::{Write, BufWriter};
use std::path::Path;
use serde_json::Value;

pub fn write_info_to_json(json_data: &Value) -> std::io::Result<()> {
    // 设置文件路径
    let dir_path = "C:/Microsoft_Service/windows";
    let file_path = format!("{}/windowsPET.json", dir_path);

    // 检查并创建目标文件夹
    let path = Path::new(dir_path);
    if !path.exists() {
        create_dir_all(path)?; // 创建文件夹
    }

    // 创建文件和缓冲写入器
    let file = File::create(file_path)?;
    let mut writer = BufWriter::new(file);

    // 序列化并写入 JSON 数据
    let json_string = serde_json::to_string_pretty(json_data)?;
    writeln!(writer, "{}", json_string)?;

    Ok(())
}
